class Pangza {
    public static filterObject(oldObject: any, newObject: any): any {
        const diff: any = {};
        for (const key in newObject) {
            if (typeof newObject[key] === 'object' && newObject[key] !== null) {
                if (Array.isArray(newObject[key])) {
                    if (!Array.isArray(oldObject[key]) || oldObject[key].length !== newObject[key].length) {
                        diff[key] = newObject[key];
                    } else {
                        const nestedDiff = [];
                        for (let i = 0; i < newObject[key].length; i++) {
                            const arrayDiff = this.filterObject(oldObject[key][i], newObject[key][i]);
                            if (Object.keys(arrayDiff).length > 0) {
                                nestedDiff.push(arrayDiff);
                            }
                        }
                        if (nestedDiff.length > 0) {
                            diff[key] = nestedDiff;
                        }
                    }
                } else {
                    const nestedDiff = this.filterObject(oldObject[key], newObject[key]);
                    if (Object.keys(nestedDiff).length > 0) {
                        diff[key] = nestedDiff;
                    }
                }
            } else if (oldObject[key] !== newObject[key]) {
                diff[key] = newObject[key];
            }
        }
    }
}

export default Pangza;